/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.agentslab.appstarter;

import aa.core.ActorMessage;
import aa.core.ActorName;
import aa.core.CyberOrg;
import aa.core.Platform;
import aa.gui.View;
import com.agentslab.constants.APIConstants;
import java.io.File;
import java.io.IOException;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author mehadihasan
 */
public class appMain {
    private static ActorName resourceBroker;
    private static ActorName gameBroker;
    private static ActorName guiActor;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        Integer iPort = new Integer(8070);

        View myView = new View(iPort);

        Platform platform = new Platform(myView,iPort);

        APIConstants.platform = platform;

        try {
            //
            // Use the system look and feel for the swing application
            //
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        platform.start();
        try{
        Thread.sleep(100);
        } catch(InterruptedException ie){
            ie.printStackTrace();
        }
        Object[] objaAgs = new Object[0];
        Object[] objaFaci = {new Long(0)};

        CyberOrg cyb = (CyberOrg)platform.createCyberOrg(new Long(90000000),new Long(90000),new Long(1000),"aa.drivers.FaciPara",objaFaci);
        APIConstants.cdmActor = platform.createActor(cyb.getFacilitator(),"aa.app.dm.CyberOrgDirectoryManager", objaAgs);
        APIConstants.gdmActor = platform.createActor(cyb.getFacilitator(),"aa.app.dm.GameDirectoryManager", objaAgs);
        APIConstants.resourceBroker =  platform.createActor(cyb.getFacilitator(),"com.agentslab.Broker.ResourceBroker", objaAgs);;
        APIConstants.gameBroker = platform.createActor(cyb.getFacilitator(),"com.agentslab.Broker.GameBroker", objaAgs);        
        APIConstants.serverActor = platform.createActor(cyb.getFacilitator(),"games.mapacman.server.Server", objaAgs);
        guiActor = platform.createActor(cyb.getFacilitator(), "com.agentslab.appstarter.GUIActor", objaAgs);
        APIConstants.guiActor = guiActor;
        APIConstants.platformCyb = cyb;

        //code for quick startup..must be commented later.

        Object[] argsreg=new Object[1];
        argsreg[0]="";


        ActorMessage am_reg = new ActorMessage(platform.getActorNameOfPlatform(),
                                               APIConstants.guiActor,
                                               "quickStartServer",
                                               argsreg,
                                               false
                                               );

        platform.sendMessage(am_reg);


    }

}
